import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/view/Home'
import Find from '@/view/Find'
import Attent from '@/view/Attent'
import Detail from '@/view/Detail'
import Admin from '@/view/Admin'

import Index from '@/view/admin/Index'
import Video from '@/view/admin/Video'
import MyAttent from '@/view/admin/Attent'
import History from '@/view/admin/History'
import Like from '@/view/admin/Like'
import Login from '@/view/admin/Login'
import Pay from '@/view/admin/Pay'
import Profit from '@/view/admin/Profit'
import Promote from '@/view/admin/Promote'

Vue.use(Router)
let routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/find',
    name: 'Find',
    component: Find
  },
  {
    path: '/attent',
    name: 'Attent',
    component: Attent
  },
  {
    path: '/detail/:vid',
    name: 'Detail',
    component: Detail
  },
  {
    path: '/admin',
    component: Admin,
    children: [
      { path: '', name: 'admin', component: Index },
      { path: 'attent', name: 'attent', component: MyAttent },
      { path: 'login', name: 'login', component: Login },
      { path: 'history', name: 'history', component: History },
      { path: 'like', name: 'like', component: Like },
      { path: 'pay', name: 'pay', component: Pay },
      { path: 'profit', name: 'profit', component: Profit },
      { path: 'promote', name: 'promote', component: Promote },
      { path: 'video', name: 'video', component: Video }
    ]
  },
  { path: '*', redirect: { name: 'Home' } }
]

let router = new Router({
  routes
})

router.afterEach((to, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  } else {
    document.title = '茄子世界'
  }
})

export default router
